<div class="row">
    <div class="col-lg-9">
        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <form method="post" id="form-list" action="index.php?r=plugins/friendlink">
                        <input type="hidden" name="action_type" value="">
                        <input type="hidden" name="plug_friendlink_id">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>LOGO</th>
                                <th>标题</th>
                                <th>链接地址</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($friendlinks as $item) {
                                ?>
                                <tr>
                                    <td><?php echo $item['imageurl']; ?></td>
                                    <td><?php echo $item['title'] ?></td>
                                    <td><?php echo $item['linkurl']; ?></td>
                                    <td><?php echo $item['seq']; ?></td>
                                    <td>
                                        <button type="button" onclick="edit(<?php echo $item['plug_friendlink_id']; ?>)" class="btn btn-primary btn-sm m-l-5">编辑</button>
                                        <button type="button" onclick="del(<?php echo $item['plug_friendlink_id']; ?>)"
                                                class="btn btn-danger btn-sm m-l-5">删除
                                        </button>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3">
        <?php
        if(isset($update_friendlink)){
            ?>
            <div class="card">
                <div class="card-title">
                    编辑友情链接
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit" action="index.php?r=plugins/friendlink">
                        <input type="hidden" name="action_type" value="updatedo">
                        <input type="hidden" name="plug_friendlink_id" value="<?php echo $update_friendlink['plug_friendlink_id']; ?>"/>
                        <div class="form-group">
                            <label>LOGO</label>
                            <input class="form-control" type="text" value="<?php echo $update_friendlink['imageurl']; ?>" name="imageurl">
                        </div>
                        <div class="form-group">
                            <label>标题</label>
                            <input class="form-control" type="text" value="<?php echo $update_friendlink['title']; ?>" name="title">
                        </div>
                        <div class="form-group">
                            <label>链接地址</label>
                            <input value="<?php echo $update_friendlink['linkurl']; ?>" name="linkurl" class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label>排序</label>
                            <input class="form-control" type="text" value="<?php echo $update_friendlink['seq']; ?>" name="seq">
                        </div>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </form>
                </div>
            </div>
            <?php
        }else{
            ?>
            <div class="card">
                <div class="card-title">
                    新增首页服务
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit" action="index.php?r=plugins/friendlink">
                        <input type="hidden" name="action_type" value="insert">
                        <input type="hidden" name="plug_friendlink_id" value="0"/>
                        <div class="form-group">
                            <label>LOGO</label>
                            <input class="form-control" type="text" value="" name="imageurl">
                        </div>
                        <div class="form-group">
                            <label>标题</label>
                            <input class="form-control" type="text" value="" name="title">
                        </div>
                        <div class="form-group">
                            <label>链接地址</label>
                            <input  name="linkurl" class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label>排序</label>
                            <input class="form-control" type="text" value="" name="seq">
                        </div>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </form>
                </div>
            </div>
            <?php
        }
        ?>
    </div>
</div>
<script>
    function del(plug_friendlink_id) {
        $("#form-list").find("input[name=plug_friendlink_id]").val(plug_friendlink_id);
        $("#form-list").find("input[name=action_type]").val("delete");
        $("#form-list").submit();
    }

    function edit(plug_friendlink_id) {
        $("#form-list").find("input[name=plug_friendlink_id]").val(plug_friendlink_id);
        $("#form-list").find("input[name=action_type]").val("update");
        $("#form-list").submit();
    }
</script>